﻿using System.Collections;
using System.Collections.Generic;
using System.Windows.Controls;

namespace Gonte.Wpf.Controls.ViewModel
{
    /// <summary>
    /// The model info describes a set of view models
    /// </summary>
    public class ItemViewModelInfo
    {
        #region Methods

        public static ItemViewModelInfo GetInfo(string viewModelInfoName)
        {
            if (!_viewModelInfos.ContainsKey(viewModelInfoName))
            {
                ItemViewModelInfo viewModelInfo = new ItemViewModelInfo();
                viewModelInfo.Populate();
                AddViewModelInfo(viewModelInfoName, viewModelInfo);

                return viewModelInfo;
            }

            return _viewModelInfos[viewModelInfoName];
        }

        #endregion

        #region Overridables

        internal virtual void Populate()
        {
        } 

        #endregion

        #region Helpers

        protected static void AddViewModelInfo(string viewModelInfoName, ItemViewModelInfo viewModelInfo)
        {
            lock (((ICollection)_viewModelInfos).SyncRoot)
            {
                _viewModelInfos.Add(viewModelInfoName, viewModelInfo);
            }
        }

        #endregion

        #region Fields

        /// <summary>
        /// The uri for the icon image that is only one for the ItemViewModel
        /// but ir can be used as the common image (expanded and collapsed) for the ContentViewModel
        /// </summary>
        public string IconUri;

        public delegate ContextMenu ContextMenuHandler(object @object);

        public ContextMenuHandler ContextMenuFactory;

        public delegate int ChildrenCompareHandler(ItemViewModel viewModel1, ItemViewModel viewModel2);

        public ChildrenCompareHandler ChildrenComparer;

        // Cached view model info
        protected static readonly Dictionary<string, ItemViewModelInfo> _viewModelInfos = new Dictionary<string, ItemViewModelInfo>(); 

        #endregion
    }
}
